<%--
  Created by IntelliJ IDEA.
  User: WYX
  Date: 2020-04-05
  Time: 9:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/statics/js/jquery-3.4.1.js"></script>

    <script>
        $(function () {
            $("#btn").click(function () {
                /*
                $.post(url , param[可以省略] , success)
                * */
                $.post("${pageContext.request.contextPath}/a2",function (data) {
                    //console.log(data);
                    var html = "";

                    /*
                    var:i可以在for循环外调用到
                    let：i限定在了for循环里面
                    * */
                    for (let i = 0; i < data.length ; i++) {
                      html +="<tr>" +
                                "<td>" +data[i].name +"</td>"+
                                "<td>" +data[i].age +"</td>"+
                                "</tr>"
                    }

                    $("#content").html(html);
                });
            })
        });
    </script>
</head>
<body>

    <input type="button" value="加载数据" id="btn">
    <table>
        <tr>
            <td>姓名：</td>
            <td>年龄：</td>
        </tr>
        <tbody id="content">
        <%--数据：后台--%>
        </tbody>
    </table>
</body>
</html>
